

var regid=/(id=)([a-zA-Z0-9]*)/;
var regpw=/(pw=)([a-zA-Z0-9]*)/;
var regnick=/(nick=)([%a-zA-Z0-9]*)/;
var urlfrom=window.location.href;
//var id = urlfrom.match(regid).splice("=")[2];
//var pw = urlfrom.match(regpw).splice("=")[2];
//var nick = urlfrom.match(regnick).splice("=")[2];
var id=$.cookie("MYID");
var pw=$.cookie("MYPW");
$.cookie("MYPW","");
var nick=$.cookie("MYNICK");
$.cookie("MYNICK","");
//var nick2 = decodeURIComponent(urlfrom.match(regnick).splice("=")[2]);
console.log(nick);
console.log(urlfrom);
//加载新闻类别列表
$.ajax({
    type:"get",
    url:zonghenewsurl+190+"&userId="+id,
    datatype:"json",
    success:function(d){
        console.log("常看新闻列表");
        console.log(d);
        for(var r=0;r< d.Data.length;r++){
            var pinyinID=pinyin.getFullChars(d.Data[r].typename).toLowerCase();
            $("#alwayspage .listplace").append("<div class='listbtn choice' id='b"+ d.Data[r].id+"' onclick='alchoicethis(this)'>"+d.Data[r].typename+"<div class='choice leftpart' id='"+pinyinID+"'></div><div class='choice rightpart'></div><img src='img/jiahao02.png' class='clickimg'/></div>")
        }
    }
});
//加载行业列表
$.ajax({
    type:"get",
    url:zonghenewsurl+191+"&userId="+id,
    datatype:"json",
    success:function(d){
        console.log("行业列表");
        console.log(d);
        for(var r=0;r< d.Data.length;r++){
            var pinyinID=pinyin.getFullChars(d.Data[r].typename).toLowerCase();
            $("#hangyepage .listplace").append("<div class='listbtn choice' id='b"+ d.Data[r].id+"' onclick='hychoicethis(this)'>"+d.Data[r].typename+"<div class='choice leftpart' id='"+pinyinID+"'></div><div class='choice rightpart'></div><img src='img/jiahao02.png' class='clickimg'/></div>")
        }
    }
});
//加载兴趣列表
$.ajax({
    type:"get",
    url:zonghenewsurl+192+"&userId="+id,
    datatype:"json",
    success:function(d){
        console.log("兴趣列表");
        console.log(d);
        for(var r=0;r< d.Data.length;r++){
            var pinyinID=pinyin.getFullChars(d.Data[r].typename).toLowerCase();
            $("#xingqupage .listplace").append("<div class='listbtn choice' id='x"+ d.Data[r].id+"' onclick='xqchoicethis(this)'>"+d.Data[r].typename+"<div class='choice leftpart' id='"+pinyinID+"'></div><div class='choice rightpart'></div><img src='img/jiahao02.png' class='clickimg'/></div>")
        }
    }
});
$(".alwaysseelistbtn").click(function(){
    $("#mainpage").css("display",'none');
    $("#alwayspage").css("display","block");
    location.href="#";//页面返回顶部
});
$(".hangyelistbtn").click(function(){
    $("#mainpage").css("display",'none');
    $("#hangyepage").css("display","block");
    location.href="#";//页面返回顶部
});
$(".xingqulistbtn").click(function(){
    $("#mainpage").css("display",'none');
    $("#xingqupage").css("display","block");
    location.href="#";//页面返回顶部
});
//选择常看新闻-----------------------------------------------------------
var alchoicenum=0;//记录选择了几个行业
function alchoicethis(e){
    if(e.className=="listbtn choice"&&alchoicenum<3){
        alchoicenum++;
        e.className+=" isclicked";
        e.getElementsByTagName("img")[0].src="img/gou03.png";
    }else if(e.className=="listbtn choice isclicked"){
        alchoicenum--;
        e.className="listbtn choice";
        e.getElementsByTagName("img")[0].src="img/jiahao02.png";
    }
    if(alchoicenum!=0){
        algobackbtn.style.display="block";
    }else{
        algobackbtn.style.display="none";
    }
}
var alnews="";
var alreg=/\d+/;
var algobackbtn=document.getElementById("alwaysgobackbtn");//下一步
algobackbtn.style.display="none";//页面初始状态 按钮隐藏
algobackbtn.onclick=function(){
    alnews="";//清除上一次的记录
    var alword="";
    $("#alwayspage").css("display","none");
    $("#mainpage").css("display",'block');
    $("#alwayspage .isclicked").each(function () {   //选择所有已经选择的标签
        var id = $(this).attr("id");
        var a=id.match(alreg);
        console.log("这是a:"+a);
        alnews+=a+",";
        alword+= $(this).html().match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]+"  ";
    });
    $(".alwayswords span").remove();
    $(".alwayswords").append("<span>"+alword+"</span>");
    alnews=alnews.substring(0,alnews.length-1);//去最后一个字符
    location.href="#";//页面返回顶部 取消搜索操作
    if(document.querySelectorAll(".xingquwords span")&&document.querySelectorAll(".xingquwords span").length>0){
        if(document.querySelectorAll(".hangyewords span")&&document.querySelectorAll(".hangyewords span").length>0){
            if(document.querySelectorAll(".alwayswords span")&&document.querySelectorAll(".alwayswords span").length>0){
                $("#mainokbtn").css("display","block");
            }
        }
    }
};
//搜索常看新闻
$("#alsearchbtn").click(function(){
    var word=$("#alsearchinput").val();
    if(!word.match(/(\s)/)&&word.length>0){
        var tomaodian=pinyin.getFullChars(word).toLowerCase();
        console.log(tomaodian);
        if($("#"+tomaodian)){
            location.href="#"+tomaodian;
            console.log($(window).scrollTop());
            $(window).scrollTop($(window).scrollTop()-124);
        }
    }
});
//常看新闻页面 返回按钮操作
$("#alwaysgoback").click(function(){
    //添加选择方法步骤
    alnews="";//清除上一次的记录
    var alword="";
    $("#alwayspage .isclicked").each(function () {   //选择所有已经选择的标签
        var id = $(this).attr("id");
        var a=id.match(alreg);
        console.log("这是a:"+a);
        alnews+=a+",";
        alword+= $(this).html().match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]+"  ";
    });
    $(".alwayswords span").remove();
    $(".alwayswords").append("<span>"+alword+"</span>");
    alnews=alnews.substring(0,alnews.length-1);//去最后一个字符
    location.href="#";//页面返回顶部 取消搜索操作


    $("#alwayspage").css("display","none");
    $("#mainpage").css("display",'block');
    location.href="#";//页面返回顶部
    if(document.querySelectorAll(".xingquwords span")&&document.querySelectorAll(".xingquwords span").length>0){
        if(document.querySelectorAll(".hangyewords span")&&document.querySelectorAll(".hangyewords span").length>0){
            if(document.querySelectorAll(".alwayswords span")&&document.querySelectorAll(".alwayswords span").length>0){
                $("#mainokbtn").css("display","block");
            }
        }
    }
});
//选择行业-----------------------------------------------------------
var hychoicenum=0;//记录选择了几个行业
function hychoicethis(e){
    if(e.className=="listbtn choice"&&hychoicenum<3){
        hychoicenum++;
        e.className+=" isclicked";
        e.getElementsByTagName("img")[0].src="img/gou03.png";
    }else if(e.className=="listbtn choice isclicked"){
        hychoicenum--;
        e.className="listbtn choice";
        e.getElementsByTagName("img")[0].src="img/jiahao02.png";
    }
    if(hychoicenum!=0){
        nextpage.style.display="block";
    }else{
        nextpage.style.display="none";
    }
}
var job="";
var reg=/\d+/;
var nextpage=document.getElementById("navigation_button");//下一步
nextpage.style.display="none";//页面初始状态 按钮隐藏
nextpage.onclick=function(){
    job="";//清除上一次的记录
    var jobword="";
    $("#hangyepage").css("display","none");
    $("#mainpage").css("display",'block');
    $("#hangyepage .isclicked").each(function () {    //选择所有已经选择的标签
        var id = $(this).attr("id");
        var a=id.match(reg);
        console.log("这是a:"+a);
        job+=a+",";
        jobword+= $(this).html().match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]+"  ";
    });
    $(".hangyewords span").remove();
    $(".hangyewords").append("<span>"+jobword+"</span>");
    job=job.substring(0,job.length-1);//去最后一个字符
    location.href="#";//页面返回顶部 取消搜索操作
    if(document.querySelectorAll(".xingquwords span")&&document.querySelectorAll(".xingquwords span").length>0){
        if(document.querySelectorAll(".hangyewords span")&&document.querySelectorAll(".hangyewords span").length>0){
            if(document.querySelectorAll(".alwayswords span")&&document.querySelectorAll(".alwayswords span").length>0){
                $("#mainokbtn").css("display","block");
            }
        }
    }
};
//搜索行业
$("#hsearchbtn").click(function(){
    var word=$("#hsearchinput").val();
    if(!word.match(/(\s)/)&&word.length>0){
        var tomaodian=pinyin.getFullChars(word).toLowerCase();
        console.log(tomaodian);
        if($("#"+tomaodian)){
            location.href="#"+tomaodian;
            console.log($(window).scrollTop());
            $(window).scrollTop($(window).scrollTop()-124);
        }
    }
});
//行业页面 返回按钮操作
$("#hygoback").click(function(){
    //添加选择方法步骤
    ob="";//清除上一次的记录
    var jobword="";
    $("#hangyepage .isclicked").each(function () {    //选择所有已经选择的标签
        var id = $(this).attr("id");
        var a=id.match(reg);
        console.log("这是a:"+a);
        job+=a+",";
        jobword+= $(this).html().match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]+"  ";
    });
    $(".hangyewords span").remove();
    $(".hangyewords").append("<span>"+jobword+"</span>");
    job=job.substring(0,job.length-1);//去最后一个字符
    location.href="#";//页面返回顶部 取消搜索操作

    $("#hangyepage").css("display","none");
    $("#mainpage").css("display",'block');
    location.href="#";//页面返回顶部
    if(document.querySelectorAll(".xingquwords span")&&document.querySelectorAll(".xingquwords span").length>0){
        if(document.querySelectorAll(".hangyewords span")&&document.querySelectorAll(".hangyewords span").length>0){
            if(document.querySelectorAll(".alwayswords span")&&document.querySelectorAll(".alwayswords span").length>0){
                $("#mainokbtn").css("display","block");
            }
        }
    }
});
//选择兴趣-----------------------------------------------------------------------
var xqchoicenum=0;//记录选择了几个行业
function xqchoicethis(e){
    if(e.className=="listbtn choice"&&xqchoicenum<3){
        xqchoicenum++;
        e.className+=" isclicked";
        e.getElementsByTagName("img")[0].src="img/gou03.png";
    }else if(e.className=="listbtn choice isclicked"){
        xqchoicenum--;
        e.className="listbtn choice";
        e.getElementsByTagName("img")[0].src="img/jiahao02.png";
    }
    if(xqchoicenum!=0){
        next.style.display="block";
    }else{
        next.style.display="none";
    }
}
//搜索兴趣
$("#xsearchbtn").click(function(){
    var word=$("#xsearchinput").val();
    if(!word.match(/(\s)/)&&word.length>0){
        var tomaodian=pinyin.getFullChars(word).toLowerCase();
        console.log(tomaodian);
        if($("#"+tomaodian)){
            location.href="#"+tomaodian;
            console.log($(window).scrollTop());
            $(window).scrollTop($(window).scrollTop()-124);
        }
    }
});
var hobby="";
var next=document.getElementById("next");//下一步
next.style.display="none";//页面初始 隐藏按钮
//兴趣页面 返回按钮操作
$("#xqgoback").click(function(){
    //添加选择方法步骤
    hobby="";//清除上一次的记录
    var hobbyword="";
    $("#xingqupage").css("display","none");
    $("#mainpage").css("display",'block');
    $("#xingqupage .isclicked").each(function () {   //选择所有已经选择的标签
        var id = $(this).attr("id");
        var a=id.match(reg);
        console.log("这是a:"+a);
        hobby+=a+",";
        hobbyword+= $(this).html().match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]+"  ";
    });
    hobby=hobby.substring(0,hobby.length-1);//去最后一个字符
    $(".xingquwords span").remove();
    $(".xingquwords").append("<span>"+hobbyword+"</span>");
    location.href="#";//页面返回顶部
    if(document.querySelectorAll(".xingquwords span")&&document.querySelectorAll(".xingquwords span").length>0){
        if(document.querySelectorAll(".hangyewords span")&&document.querySelectorAll(".hangyewords span").length>0){
            if(document.querySelectorAll(".alwayswords span")&&document.querySelectorAll(".alwayswords span").length>0){
                $("#mainokbtn").css("display","block");
            }
        }
    }
});
next.onclick=function(){
    hobby="";//清除上一次的记录
    var hobbyword="";
    $("#xingqupage").css("display","none");
    $("#mainpage").css("display",'block');
    $("#xingqupage .isclicked").each(function () {   //选择所有已经选择的标签
        var id = $(this).attr("id");
        var a=id.match(reg);
        console.log("这是a:"+a);
        hobby+=a+",";
        hobbyword+= $(this).html().match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]+"  ";
    });
    hobby=hobby.substring(0,hobby.length-1);//去最后一个字符
    $(".xingquwords span").remove();
    $(".xingquwords").append("<span>"+hobbyword+"</span>");
    location.href="#";//页面返回顶部
    if(document.querySelectorAll(".xingquwords span")&&document.querySelectorAll(".xingquwords span").length>0){
        if(document.querySelectorAll(".hangyewords span")&&document.querySelectorAll(".hangyewords span").length>0){
            if(document.querySelectorAll(".alwayswords span")&&document.querySelectorAll(".alwayswords span").length>0){
                $("#mainokbtn").css("display","block");
            }
        }
    }
};
$("#mainokbtn").click(function(){
    $.ajax({
        type: "post",
        datatype: "json",
        url: updateuserurl,
        data:{"userId":id,"nick":nick,"city":"","cover":"","pw":pw,"sex":"","userAva":"","sign":"","score":"","education":"","visitedcity":"","hobby":hobby,"job":job,"news":alnews},
        success:function(data){
            console.log(data);
            //$.cookie("tohrefurl",tohrefurl);//个人设置页面最终跳转地址
            if($.cookie("tohrefurl")){
                location.href=$.cookie("tohrefurl");
            }else{
                location.href="home.html";
            }
        }
    })
})
//键盘搜索--------------------------------------
document.onkeydown=function(event){
    var e=event||window.event||arguments.callee.caller.arguments[0];
    if(e&&e.keyCode==13){
        //搜索行业
        if($("#hangyepage").css("display")==="block"){
            var word=$("#hsearchinput").val();
            if(!word.match(/(\s)/)&&word.length>0){
                var tomaodian=pinyin.getFullChars(word).toLowerCase();
                console.log(tomaodian);
                if($("#"+tomaodian)){
                    location.href="#"+tomaodian;
                    console.log($(window).scrollTop());
                    $(window).scrollTop($(window).scrollTop()-124);
                }
            }
        }
        //搜索兴趣
        else if($("#xingqupage").css("display")==="block"){
            var word=$("#xsearchinput").val();
            if(!word.match(/(\s)/)&&word.length>0){
                var tomaodian=pinyin.getFullChars(word).toLowerCase();
                console.log(tomaodian);
                if($("#"+tomaodian)){
                    location.href="#"+tomaodian;
                    console.log($(window).scrollTop());
                    $(window).scrollTop($(window).scrollTop()-124);
                }
            }
        }
        //搜索新闻
        else if($("#alwayspage").css("display")==="block"){
            var word=$("#alsearchinput").val();
            if(!word.match(/(\s)/)&&word.length>0){
                var tomaodian=pinyin.getFullChars(word).toLowerCase();
                console.log(tomaodian);
                if($("#"+tomaodian)){
                    location.href="#"+tomaodian;
                    console.log($(window).scrollTop());
                    $(window).scrollTop($(window).scrollTop()-124);
                }
            }
        }
    }
};
$("#maingoback").click(function(){
    location.href="index.html";
});